struct Solution {}

impl Solution {
  pub fn good_days_to_rob_bank(security: Vec<i32>, time: i32) -> Vec<i32> {
  let l = security.len();
  if time == 0 {
    return (0..l).map(|i| i as i32).collect();
  }
  if time * 2 + 1 > l as i32 {
    return vec![];
  }
  let mut ret = vec![];
  let time = time as usize;
  let mut c = time as usize;
  while c + time < l {
    let mut t = c;
    let mut le = security[c];
    let mut re  = security[c];
    for i in 1..time+1 {
      if security[c - i] < le {
        t += 1;
        break;
      }
      if security[c + i] < re {
        t += i;
        break;
      }
      le = security[c - i];
      re = security[c + i];
    }
    if t == c {
      ret.push(c as i32);
      let mut edge = security[c + time];
      c += 1;
      while c + time < l && security[c + time] >= edge && security[t] == security[c] {
        ret.push(c as i32);
        edge = security[c + time];
        c += 1;
      }
    }   
    else {
      c = t;
    }
  }
  ret
  }
}